﻿#if UNITY_EDITOR 
using UnityEngine;

namespace Gp.Scripts.Editor
{
    /// <summary>
    /// 仅用于Editor 下的摄像机管理
    /// </summary>
    [ExecuteAlways]
    public class SceneCameraHook : MonoBehaviour
    {
        public static bool ShowSceneCamera = true;
        public static SceneCameraHook Instance = null;
        public new Camera camera;
        private void Awake()
        {
            if (Application.isPlaying) Destroy(gameObject);
            else
            {
                Instance = this;
                camera = GetComponentInChildren<Camera>();
            }

        }


        private void Update()
        {
            if (! ShowSceneCamera) DestroyImmediate(gameObject);
            if (Application.isPlaying) Destroy(gameObject);
        }
        

        

        private void OnDestroy()
        {
            Debug.Log($"Editor-[{nameof(SceneCameraHook)}]: Auto destroyed successfully !");
        }
    }
}

#endif